package net.zhuike.novel.app.ui.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import net.zhuike.novel.app.R;
import net.zhuike.novel.app.bean.BookMixAToc;
import net.zhuike.novel.app.bean.BookSit;
import net.zhuike.novel.app.bean.user.MenuModel;
import net.zhuike.novel.app.ui.utils.FileUtils;
import net.zhuike.novel.app.ui.utils.SharedPreferencesUtil;

import java.util.List;

import framework.common.easyadpter.abslistview.EasyLVAdapter;
import framework.common.easyadpter.abslistview.EasyLVHolder;

/**
 * @author wq.
 * @date 17/6/19.
 */
public class TocSourceListAdapter extends EasyLVAdapter<BookSit.Chapters> {

    private int currentChapter;
    private String bookId;

    private boolean isEpub = false;

    public TocSourceListAdapter(Context context, List<BookSit.Chapters> list, String bookId) {
        super(context, list, R.layout.item_book_read_toc_list);
        this.bookId = bookId;
    }

    @Override
    public void convert(EasyLVHolder holder, int position, BookSit.Chapters chapters) {
        TextView tvTocItem = holder.getView(R.id.tvTocItem);
        tvTocItem.setText(chapters.name);
        Drawable drawable;

        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.text_dark_color));
        if(!(SharedPreferencesUtil.getInstance().getString(bookId+"source"+position,"")==null||SharedPreferencesUtil.getInstance().getString(bookId+"source"+position,"").equals(""))){
            if (SharedPreferencesUtil.getInstance().getString(bookId + "source" + position, "").equals(String.valueOf(position))) {

                drawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_theme_selected);
            } else {
                drawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_toc_item_normal);
            }
        }else {
            drawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_toc_item_normal);
        }
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvTocItem.setCompoundDrawables(drawable, null, null, null);
    }

    public void setCurrentChapter(int chapter) {
        currentChapter = chapter;
        notifyDataSetChanged();
    }

    public void setEpub(boolean isEpub) {
        this.isEpub = isEpub;
    }
}
